var dat = [];
function ld(id){
    $.post('htz/functionfield/show',{id: id},function (data) {
        dat = data.obj;
        layui.use(['tree', 'util',"layer"], function(){
            var tree = layui.tree
                ,layer = layui.layer
                ,util = layui.util
                // 模拟数据
                ,data = dat;

            //基本演示
            tree.render({
                elem: '#test12'
                ,data: data
                ,showCheckbox: true  //是否显示复选框
                ,id: 'demoId1'
                ,isJump: true //是否允许点击节点时弹出新窗口跳转
                ,click: function(obj){
                    var data = obj.data;  //获取当前点击的节点数据
                    layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
                }
            });

            //按钮事件
            util.event('lay-demo', {
                getChecked: function(othis){
                    var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                    if (checkedData!=""){
                        $.ajax({
                            type: "post",
                            url: "htz/functionfield/update",
                            data: JSON.stringify(checkedData),
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            success:function (data) {

                                if (data.obj){
                                    layer.msg("修改成功");
                                }
                            }
                        })
                    } else {
                        layer.msg("权限不能为空")
                    }

                    // layer.alert(JSON.stringify(checkedData), {shade:0});
                    // console.log(checkedData);
                }
                ,setChecked: function(){
                    tree.setChecked('demoId1', [12, 16]); //勾选指定节点
                }
                ,reload: function(){
                    //重载实例
                    tree.reload('demoId1', {

                    });

                }
            });
            tree.render({
                elem: '#test4'
                ,data: [{
                    title: '优秀'
                    ,children: [{
                        title: '80 ~ 90'
                    },{
                        title: '90 ~ 100'
                    }]
                },{
                    title: '良好'
                    ,children: [{
                        title: '70 ~ 80'
                    },{
                        title: '60 ~ 70'
                    }]
                },{
                    title: '要努力奥'
                    ,children: [{
                        title: '0 ~ 60'
                    }]
                }]
                ,accordion: true
            });

            //点击节点新窗口跳转
            tree.render({
                elem: '#test5'
                ,data: data
                ,isJump: true  //link 为参数匹配
            });
        });
    })
}